#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#define endl "\n"
using namespace std;
int aa[11];
const int N=150;
int n,k=0;
bool a[N],a1[2*N],a2[2*N];//
bool panduan(int x,int y)
{
    if(!a[y]&&!a1[x-y+10]&&!a2[x+y])//当x=y和x+y等于定值
    {
        return true;
    }
        return false;
}
void dfs(int x)
{
    if (x >= n) {
        k++;
        return;
    }

    for(int y=0;y<n;y++ )
    {
        if(panduan(x,y))
        {
            //if(x==n-1)
            //{
            //    k++;
            //}
            a[y]=a1[x-y+10]=a2[x+y]=true;
            dfs(x+1);
            a[y]=a1[x-y+10]=a2[x+y]=false;//
        }
    }

}
int main()
{
    while(1)
    {
        cin>>n;
        if(n==0)
            return 0;
        if(aa[n]==0)
        {
            k=0;
            dfs(0);
            aa[n]=k;

        }
        cout<<aa[n]<<endl;
    }
    return 0;
}
